package com.flame.core.utils;

public final class StringUtils {

    private StringUtils() {
    }

    public static boolean hasText(String str) {
        return org.springframework.util.StringUtils.hasText(str);
    }

    /**
     * xxx_xxxx_xxx -> XxxXxxxXxx or xxxXxxxXxx
     *
     * @param str   underscore str
     * @param index 开始位置
     * @param flag  首字母大写
     * @return
     */
    public static String mapUnderscoreToCamelCase(String str, int index, boolean flag) {
        char[] chs = str.toCharArray();
        StringBuilder sb = new StringBuilder();
        while (index < chs.length) {
            if (chs[index] == '_') {
                flag = true;
                index++;
                continue;
            }
            if (flag) {
                if (chs[index] >= 'a' && chs[index] <= 'z') {
                    sb.append((char) (chs[index] - 'a' + 'A'));
                    flag = false;
                    index++;
                } else {
                    sb.append(chs[index]);
                    flag = false;
                    index++;
                }
            } else {
                sb.append(chs[index]);
                index++;
            }
        }
        return sb.toString();
    }

    public static String removePrefix(String prefix, String str) {
        if (str.startsWith(prefix)) {
            str = str.substring(prefix.length());
        }
        return str;
    }
}
